package com.example.a2302fx

import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.a2302fx.databinding.ActivityWebViewBinding
import com.example.base.mvvm.BaseViewActivity

@Route(path = "/app/WebViewActivity")
class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {

    @Autowired
    @JvmField
    var url = "http://www.baidu.com"
    override fun initData() {

    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        binding.wv.loadUrl(url)
        binding.wv.webViewClient = WebViewClient()
        val webChromeClient = object:WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                if(newProgress==100){
                    binding.pb.isVisible = false
                }
                binding.pb.progress = newProgress
            }
        }
        binding.wv.webChromeClient = webChromeClient
        binding.wv.settings.javaScriptEnabled = true
    }

    override fun getLayout(): Int = R.layout.activity_web_view

}